package org.microsites.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.microsites.domain.dao.UserDAO;
import org.microsites.domain.model.Entity;
import org.microsites.domain.model.User;
import org.microsites.service.UserService;
import org.microsites.util.UserContext;

public class UserServiceImpl extends GenericServiceImpl<User> implements UserService {

	private UserDAO userDAO;
	private UserContext userCtx;

	@Override
	public User login(String uid, String pwd) {
		User user = userDAO.login(uid, pwd);
		userCtx.setUser(user);
		return user;
	}

    @Override
    public User getCurrentUser() {
        return userCtx.getUser();
    }

	@Override
	public void logout() {
		userCtx.reset();
	}

	@Override
	public UserDAO getDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public UserContext getUserCtx() {
		return userCtx;
	}

	public void setUserCtx(UserContext userCtx) {
		this.userCtx = userCtx;
	}

    @Override
    public List<Entity> loadPath(Long id) {
        if (id == null) return new ArrayList<Entity>();

        User d = this.load(id);
        if (d == null) return new ArrayList<Entity>();
        
        List<Entity> list = new ArrayList<Entity>();
        list.add(d);

        return list;
    }
}
